package main

import (
	"gitee.com/injoyai/goutil/net/conn/v2"
	"time"
)

func main() {

	addr := "127.0.0.1:10086"

	//conn.RetryDialTCP(addr, func(c *conn.Conn) {
	//	c.Debug()
	//	c.SetDealFunc(func(msg *conn.Msg) {
	//		//log.Println("收到:", msg.Hex())
	//	})
	//})

	c := conn.RedialTCP(addr, func(c *conn.Conn) {
		c.SetPrintWithASCII()
		c.Debug()
		c.SetDealFunc(func(msg *conn.Message) {
			//log.Println("收到:", msg.Hex())
		})
		c.SetKeepAlive(time.Second * 5)
		go func() {
			for {
				time.Sleep(time.Second * 8)
				if err := c.WriteString("xxx"); err != nil {
					return
				}
			}
		}()
		//c.SetTag("new")
		//go func() {
		//	//return
		//	for {
		//		time.Sleep(time.Second * 5)
		//		if err := c.WriteString(io.DefaultPing); err != nil {
		//			return
		//		}
		//	}
		//}()
	})
	if false {
		c.SetKeepAlive(time.Second * 5)
		time.Sleep(time.Second * 10)
		c.SetKeepAlive(time.Second * 3)
		time.Sleep(time.Second * 10)
		c.SetKeepAlive(time.Second * 0)
		time.Sleep(time.Second * 10)
		c.SetKeepAlive(time.Second * 4)
		//c.Close()
	}

	//go func() {
	//	for i := 0; i < 100; i++ {
	//		//go func() {
	//		for {
	//			if err := c.Send("666"); err != nil {
	//				log.Println(err)
	//			}
	//			time.Sleep(time.Second * 8)
	//		}
	//		//}()
	//	}
	//}()

	select {}

}
